//
//  ProjectInfoDetailViewController.m
//  mhome
//
//  Created by YaSha_Tom on 2018/12/7.
//  Copyright © 2018年 刘春雷. All rights reserved.
//

#import "ProjectInfoDetailViewController.h"
#import "YSPMSInfoDetailHeaderCell.h"

@interface ProjectInfoDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *contentDataArray;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSourceArray;
@end

@implementation ProjectInfoDetailViewController
- (NSMutableArray *)contentDataArray {
    if(!_contentDataArray){
        _contentDataArray = [NSMutableArray array];
    }
    return _contentDataArray;
}
- (NSMutableArray *)dataSourceArray {
    if(!_dataSourceArray){
        _dataSourceArray = [NSMutableArray array];
    }
    return _dataSourceArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"项目信息详情";
    [self dealWithData];
    [self initUI];
    
}
- (void)dealWithData {
    [self.dataSourceArray addObjectsFromArray:@[@"投标类型",
                                                @"合同形式",
                                                @"施工面积（㎡）",
                                                @"施工范围",
                                                @"质量目标",
                                                @"技术标准",
                                                @"计划开工",
                                                @"计划竣工",
                                                @"保修期限 （年）",
                                                @"合同号",
                                                @"保险时间",
                                                @"考核价 (万元)",
                                                @"考核费率（%）",
                                                @"中标交底",
                                                @"项目交底"
                                                ]];
    if ([self.model.isConSign isEqualToString:@"0"]) {
        [self.dataSourceArray addObject:@"合同签订说明"];
        [self.dataSourceArray removeObject:@"合同号"];
    }
    if ([self.model.isWinBid isEqualToString:@"0"]) {
        [self.dataSourceArray addObject:@"中标交底说明"];
        [self.dataSourceArray removeObject:@"中标交底"];
    }
    if ([self.model.isProBid isEqualToString:@"0"]) {
        [self.dataSourceArray addObject:@"项目交底说明"];
        [self.dataSourceArray removeObject:@"项目交底"];
    }
    if ([self.model.examSign isEqualToString:@"0"]) {
        [self.dataSourceArray addObject:@"考核签订说明"];
        [self.dataSourceArray removeObject:@"考核价 (万元)"];
        [self.dataSourceArray removeObject:@"考核费率（%）"];
    }
    if ([self.model.isProIns isEqualToString:@"0"]) {
        [self.dataSourceArray addObject:@"项目保险说明"];
        [self.dataSourceArray removeObject:@"保险时间"];
    }
    [self.dataSourceArray addObject:@"合同重要条款"];
    [self.contentDataArray addObject:self.model.bidTypeName];
    [self.contentDataArray addObject:self.model.contFormName];
    [self.contentDataArray addObject:[NSString stringWithFormat:@"%@",self.model.conArea]];
    
    [self.contentDataArray addObject:[self.model.conScope isEqualToString:@" "]?self.model.conScope:@"-"];
    [self.contentDataArray addObject:[self.model.qtarget isEqualToString:@" "]?self.model.qtarget:@"-"];
    [self.contentDataArray addObject:[self.model.tecStand isEqualToString:@" "]?self.model.tecStand:@"-"];
    [self.contentDataArray addObject:self.model.planStart];
    [self.contentDataArray addObject:self.model.planEnd];
    [self.contentDataArray addObject:[NSString stringWithFormat:@"%@",self.model.repairStr]];
    [self.contentDataArray addObject:[self.model.isConSign isEqual:@1] ? self.model.conCode : @"合同号"];
    [self.contentDataArray addObject:[self.model.isProIns isEqual:@1] ? self.model.proInsDate :@"保修时间"];
    [self.contentDataArray addObject:[self.model.examSign isEqual:@1] ? self.model.assePrice :@"考核价"];
     [self.contentDataArray addObject:[self.model.examSign isEqual:@1] ? self.model.asseRate :@"考核费率"];
    [self.contentDataArray addObject:[self.model.isWinBid isEqual:@1] ? @"已完成" :@"已完成1"];
    [self.contentDataArray addObject:[self.model.isProBid isEqual:@1] ? @"已完成" :@"已完成2"];
    if ([self.model.isConSign isEqualToString:@"0"]) {
        [self.contentDataArray addObject:self.model.conSignRemark];
        [self.contentDataArray removeObject:@"合同号"];
    }
    if ([self.model.examSign isEqualToString:@"0"]) {
        [self.contentDataArray addObject:self.model.examSignRemark];
        [self.contentDataArray removeObject:@"考核价"];
        [self.contentDataArray removeObject:@"考核费率"];
        
    }
    if ([self.model.isProIns isEqualToString:@"0"]) {
        [self.contentDataArray addObject:self.model.proInsRemark];
        [self.contentDataArray removeObject:@"保修时间"];
    }
    if ([self.model.isWinBid isEqualToString:@"0"]) {
        [self.contentDataArray addObject:self.model.winBidRemark];
        [self.contentDataArray removeObject:@"已完成1"];
    }
    if ([self.model.isProBid isEqualToString:@"0"]) {
        [self.contentDataArray addObject:self.model.proBidRemark];
        [self.contentDataArray removeObject:@"已完成2"];
    }
    [self.contentDataArray addObject:[self.model.conImpClause isEqualToString:@" "]?self.model.conImpClause:@"-"];
    [self.tableView reloadData];
}
- (void)initUI {
    self.tableView = [[UITableView alloc]initWithFrame:CGRects(0, 0, 375, 635) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSourceArray.count + 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200*kHeightScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(indexPath.section == 0 && indexPath.row == 0){
        return 80*kHeightScale;
    }else{
        return UITableViewAutomaticDimension;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YSPMSInfoDetailHeaderCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[YSPMSInfoDetailHeaderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoDetailCell"];
    }
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.separatorInset = UIEdgeInsetsMake(0, kSCREEN_WIDTH, 0, 0);
    if (indexPath.row == 0) {
        UILabel *projectLabel = [[UILabel alloc]init];
        projectLabel.textAlignment = NSTextAlignmentCenter;
        projectLabel.font = [UIFont systemFontOfSize:17];
        projectLabel.adjustsFontSizeToFitWidth = YES;
        projectLabel.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0];
        projectLabel.numberOfLines = 0;
        projectLabel.text = self.model.name;
        [cell addSubview:projectLabel];
        [projectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(cell.mas_centerX);
            make.centerY.mas_equalTo(cell.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(kSCREEN_WIDTH-80*kWidthScale, 80*kWidthScale));
        }];
        
    }else{
        cell.titleLabel.text = self.dataSourceArray[indexPath.row-1];
        cell.contentLabel.text = self.contentDataArray[indexPath.row-1];
        
    }
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
